import { Button } from 'antd'

import { modelStore, drawerStore } from '../Config/zustand'


export const ButtonMapping = ({ config }) => {
    const { updateModel } = modelStore()
    const { updateDrawer } = drawerStore()
    const drawerStoreMapping = { 'model': updateModel, 'drawer': updateDrawer }
    const { title, smallTitle, modalType, page, data } = config

    return (
        <Button
            type={config?.type || 'link'}
            icon={config?.icon || ''}
            shape={config?.shape || 'default'}
            iconPosition={config?.iconPosition || 'start'}
            ghost={config?.ghost}
            disabled={config?.disabled}
            danger={config?.danger}
            onClick={() => drawerStoreMapping[modalType]({
                close: config?.close,
                width: config?.width,
                title: smallTitle || title,
                type: page,
                data,
            })}
        >
            {title}
        </Button>
    )
}